package lax.task.com;

import java.util.Timer;
import java.util.TimerTask;

public class TaskRun {
    private Timer timer;
    private int error = 0;

    public void AddTask(long time, String url, String name) {
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                String return_str = HttpClient.doGet(url);
                if (return_str.equals("ok") || error >= 9) {
                    System.out.println("cancel" + name);
                    timer.cancel();
                } else {
                    System.out.println("error");
                    error++;
                }
            }
        };
        timer = new Timer();
        timer.scheduleAtFixedRate(task, time, AppData.taskRunTime);
    }

}
